
import { getTicketDetail, getShopList } from '@mall/api/good'
import router from "@src/router";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import mall from "@src/store/mall";
import base from "@src/store/base";
import $math from "@src/common/math"
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: mall,
    fields: ['curLocation'],
    actions: ['initLocation']
  },
  {
    store: base,
    fields: ['themeColor', 'themeTitleColor'],
  }],
  properties: {
    //商品信息
    items: {
      type: Array
    },
    //店铺信息
    storeInfo: {
      type: Object
    },
    //订单状态
    status: {
      type: String
    },
    ticketList: {
      type: Array,
      value: []
    },
    orderAmounts: {
      type: Array,
      value: []
    },
    subType:{
      type:String,
      value:""
    },
    orderPresell: {
      type: Object,
      observer: function (orderPresell) {
        let subFee = $math.add(orderPresell.remainingFee / 100, orderPresell.depositFee / 100)
        this.setData({ subFee })
      }
    },
    //实付金额
    tradeFee: {
      type: Number
    },
    //商品预售信息
    goodsPresell: {
      type: Object,
    },
    bookingStatus:{
      type:Boolean,
    }
  },
  observers: {
  },
  options: {
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    ticketlist: [],
    hiddenticket: true,
    ticketObj: {},
    pageAddressObj: null,
    hiddenGoodsList: true,
    //定金加尾款
    subFee: null
  },

  /**
   * 组件生命周期
   */
  lifetimes: {
    attached: function (val) {
      const self = this;
      wx.getLocation({
        type: 'wgs84',
        success: function (res) {
          let pageAddressObj = {
            latitude: res.latitude,
            longitude: res.longitude
          }
          self.setData({
            pageAddressObj: pageAddressObj
          })
          console.log("小程序定位", res);

        },
        fail: function (res) {
          console.log(res);
        }
      })

    },
    ready: function (val) {

    },
    moved: function () {
    },
    detached: function () {

    },
  },

  /**
 * 组件所在页面生命周期
 */
  pageLifetimes: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    againBuy(e) {
      let item = e.currentTarget.dataset.item;
      let data = {
        goodsSerial: item.goodsSerial,
        storeId: item.storeId
      }
      router.push({ name: 'mall/goods-detail', params: data })
      //向父组件发出再次购买事件
      // this.triggerEvent('againBuy', temp)
    },
    //组装items 券数据
    assemblyTicketData() {
      let ticketlist = this.data.ticketlist
      ticketlist.forEach(item => {
        item.tickethidden = true
      })
      this.setData({
        ticketlist: ticketlist
      })
      console.log("组装好之后", this.data.ticketlist)
    },
    //显示券详情
    handleShowCoupon(e) {
      let item = e.currentTarget.dataset.item
      if (item.itemType === 'COUPON') {
        this.selectComponent("#couponDetail").open(item);
      } else {
        this.selectComponent("#couponDetailNew").open(item);
      }
    },
    openSaleDialog() {
      this.selectComponent("#goodSaleDialog").open()
    }
  }
})
